﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TalentRecruitmentSystem.Service
{
    public class CompanyInfoServices
    {
        Entities entity = new Entities();
        /// <summary>
        /// 添加企业信息
        /// </summary>
        /// <param name="companyInfo"></param>
        /// <returns></returns>
        public bool add(CompanyInfo companyInfo)
        {
            entity.CompanyInfo.AddObject(companyInfo);
            if (entity.SaveChanges() > 0)
            {
                return true;
            }
            return false;
        }
        public bool delete(CompanyInfo companyInfo)
        {
            return false;
        }
        /// <summary>
        /// 根据企业名获取企业信息
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public CompanyInfo getCompanyInfoByName(string name)
        {
            CompanyInfo companyInfo = new CompanyInfo();
            bool b = entity.CompanyInfo.Any(c => c.CompanyName == name);
            if (b == true)
            {
                return entity.CompanyInfo.Single(c => c.CompanyName == name);
            }
            else
                return null;
        }
        public CompanyInfo getCompanyInfoByUserName(string name)
        {
            CompanyInfo companyInfo = new CompanyInfo();
            bool b = entity.CompanyInfo.Any(c => c.UserName == name);
            if (b == true)
            {
                return entity.CompanyInfo.Single(c => c.UserName == name);
            }
            else
                return null;
        }
        public List<CompanyInfo> getCompanyInfosByParameter(string p1, string p2, string p3)
        {
            return entity.CompanyInfo.Where(c => c.TradebBongTo == p1 && c.Publishposition == p2 && c.WorkPlace == p3).ToList();
        }
        /// <summary>
        /// 根据id查询企业信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public CompanyInfo getCompanyInfoByID(int id)
        {
            return entity.CompanyInfo.Single(c => c.CompanyID == id);
        }
        /// <summary>
        /// 更新企业信息
        /// </summary>
        /// <param name="companyInfo"></param>
        /// <returns></returns>
        public bool update(CompanyInfo companyInfo)
        {
            entity.CompanyInfo.ApplyCurrentValues(companyInfo);
            if(entity.SaveChanges()>0)
            {
                return true;
            }
            return false;
        }
    }
}